<template>
    <el-dialog
            :title="!dataForm.id ? '新增' : '修改'"
            :close-on-click-modal="false"
            :visible.sync="visible">
        <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="120px">
                            <el-form-item label="主键ID" prop="id">
                        <el-input v-model.number="dataForm.id" placeholder="主键ID"></el-input>
                </el-form-item>
                <el-form-item label="用户ID（关联用户表，此处不设外键）" prop="userId">
                        <el-input v-model.number="dataForm.userId" placeholder="用户ID（关联用户表，此处不设外键）"></el-input>
                </el-form-item>
                <el-form-item label="个人日程ID（关联个人日程表，此处不设外键）" prop="personalScheduleId">
                        <el-input v-model.number="dataForm.personalScheduleId" placeholder="个人日程ID（关联个人日程表，此处不设外键）"></el-input>
                </el-form-item>
                <el-form-item label="团队日程ID（关联团队日程表，此处不设外键）" prop="teamScheduleId">
                        <el-input v-model.number="dataForm.teamScheduleId" placeholder="团队日程ID（关联团队日程表，此处不设外键）"></el-input>
                </el-form-item>
                <el-form-item label="冲突时间" prop="conflictTime">
                        <el-date-picker
                                v-model="dataForm.conflictTime"
                                type="datetime"
                                placeholder="冲突时间">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="是否已解决" prop="resolved">
                        <el-input v-model="dataForm.resolved" placeholder="是否已解决"></el-input>
                </el-form-item>
                <el-form-item label="解决时间" prop="resolvedAt">
                        <el-date-picker
                                v-model="dataForm.resolvedAt"
                                type="datetime"
                                placeholder="解决时间">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="创建时间" prop="createdAt">
                        <el-date-picker
                                v-model="dataForm.createdAt"
                                type="datetime"
                                placeholder="创建时间">
                        </el-date-picker>
                </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
    </el-dialog>
</template>

<script>
    export default {
      data () {
        return {
          visible: false,
          dataForm: {
            id: null,
            userId: null,
            personalScheduleId: null,
            teamScheduleId: null,
            conflictTime: null,
            resolved: null,
            resolvedAt: null,
            createdAt: null
          },
          dataRule: {
            id: [
                        { required: true, message: '主键ID不能为空', trigger: 'blur' }
            ],
            userId: [
                        { required: true, message: '用户ID（关联用户表，此处不设外键）不能为空', trigger: 'blur' }
            ],
            personalScheduleId: [
                        { required: true, message: '个人日程ID（关联个人日程表，此处不设外键）不能为空', trigger: 'blur' }
            ],
            teamScheduleId: [
                        { required: true, message: '团队日程ID（关联团队日程表，此处不设外键）不能为空', trigger: 'blur' }
            ],
            conflictTime: [
                        { required: true, message: '冲突时间不能为空', trigger: 'blur' }
            ],
            resolved: [
                        { required: true, message: '是否已解决不能为空', trigger: 'blur' }
            ],
            resolvedAt: [
                        { required: true, message: '解决时间不能为空', trigger: 'blur' }
            ],
            createdAt: [
                        { required: true, message: '创建时间不能为空', trigger: 'blur' }
            ]
          }
        }
      },
      methods: {
        init (id) {
          this.dataForm.id = id || 0
          this.visible = true
          this.$nextTick(() => {
            this.$refs['dataForm'].resetFields()
            this.dataForm.id = id || 0
            if (this.dataForm.id) {
              this.$http({
                url: this.$http.adornUrl(`/app/schedule_conflict/info/${this.dataForm.id}`),
                method: 'get',
                params: this.$http.adornParams()
              }).then(({data}) => {
                if (data && data.code === 0) {
                  this.dataForm = data.appscheduleconflict
                }
              })
            }
          })
        },
            // 表单提交
        dataFormSubmit () {
          this.$refs['dataForm'].validate((valid) => {
            if (valid) {
              this.$http({
                url: this.$http.adornUrl(`/app/schedule_conflict/${!this.dataForm.id ? 'save' : 'update'}`),
                method: 'post',
                data: this.$http.adornData(this.dataForm)
              }).then(({data}) => {
                if (data && data.code === 0) {
                  this.$message({
                    message: '操作成功',
                    type: 'success',
                    duration: 1500,
                    onClose: () => {
                      this.visible = false
                      this.$emit('refreshDataList')
                    }
                  })
                } else {
                  this.$message.error(data.msg)
                }
              })
            }
          })
        }
      }
    }
</script>